package cn.SiFuLan.controls;

import cn.SiFuLan.dao.IbrandDao;
import cn.SiFuLan.dao.IspuDao;
import cn.SiFuLan.dao.impl.brandDaoImpl;
import cn.SiFuLan.dao.impl.spuDaoImpl;
import cn.SiFuLan.entity.brandEntity;
import cn.SiFuLan.entity.spuEntity;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/admin/index.do")
public class spuServlt extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");


        IspuDao ispuDao=new spuDaoImpl();
        spuEntity spuEntity=new spuEntity();
        String name=request.getParameter("uname");
        spuEntity.setSpu_Name(name);
        String id=request.getParameter("rid");
        if(id!=null && !id.equals("")){
            spuEntity.setBrand_id(Integer.parseInt(id));
        }
        List<spuEntity> spu=ispuDao.aall(spuEntity);


        IbrandDao ibrandDao=new brandDaoImpl();
        List<brandEntity> list1=ibrandDao.All();
        request.setAttribute("list1",list1);
        request.setAttribute("spu",spu);
        request.getSession().setAttribute("spuEntity",spuEntity);
        request.getRequestDispatcher("shouye.jsp").forward(request,response);
    }
}
